package com.sds.emp.services.user.test;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import com.sds.emp.services.user.UserService;
import com.sds.emp.services.user.vo.SearchVO;
import com.sds.emp.services.user.vo.UserVO;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:/spring/context-user-client.xml" })
public class UserServiceClient {

    // TODO - define dependency injection for
    // UserService
    private UserService client;
    private Log logger = LogFactory.getLog(UserService.class);

    @Test
    public final void testAddUser() throws Exception {
        UserVO userVO = new UserVO();
        try {
            userVO.setUserId("admin");
            client.addUser(userVO);
        } catch (Exception e) {
            logger.error("Fail to add user.", e);
            Assert.fail();
        }
    }

    @Test
    public final void testUpdateUser() throws Exception {
        UserVO userVO = new UserVO();
        try {
            userVO.setUserId("admin");
            userVO.setUserName("");
            userVO.setEmail("anyframe@samsung.com");
            client.updateUser(userVO);
        } catch (Exception e) {
            logger.error("Fail to update user.", e);
            Assert.fail();
        }
    }

    @Test
    public final void testGetUserList() throws Exception {
        SearchVO searchVO = new SearchVO();
        searchVO.setSearchKeyword("ADMIN");
        try {
            client.getUserList(searchVO);
        } catch (Exception e) {
            logger.error("Fail to get user list.", e);
            Assert.fail();
        }
    }
}
